//右滑关闭
mui.init({
	swipeBack: true,
})
var fs = true;
var UserNO = localStorage.getItem("UserName");
window.onload = function() {

	mui.plusReady(function() {
		var currentwindow = plus.webview.currentWebview();
		if (currentwindow.WorkOrderNO != '' && currentwindow.WorkOrderNO != undefined) {
			$("#WorkOrderNO").val(currentwindow.WorkOrderNO);
			$("#MatNO").val(currentwindow.MaterialNO);
			$("#MaterialName").val(currentwindow.MaterialName);
		} else {
			mui.toast("未带入参数。", {
				duration: '1000',
				type: 'div'
			});
		}

		//下线条码扫描
		$("#OutBar").keyup(function(event) {
			if (event.keyCode == 13) {
				$("#InBar").val('');

				$("#InBar").focus();
			}

		});

		//上线条码扫描
		$("#InBar").keyup(function(e) {

			if (e.keyCode == 13) {
				var OutBarCodeNO = $("#OutBar").val();
				var InBarCodeNO = $("#InBar").val();
				var workorderNO = $("#WorkOrderNO").val();
				if (OutBarCodeNO === null || OutBarCodeNO === undefined) {
					mui.toast("请扫描条码。", {
						duration: '1000',
						type: 'div'
					});
					OutBarCodeNO.focus();
				}
				xccpostAsync("JyhstWebASHX.ashx", {
					Action: "SMTConnectMaterialBarcode",
					InBarCodeNO: InBarCodeNO,
					workorderNO: workorderNO,
					OutBarCodeNO: OutBarCodeNO,
					UserNO: UserNO
				}, function(data) {
					console.log(JSON.stringify(data));

					if (data.Code == "200") {
						$("#txtResult").val(InBarCodeNO + "上料成功,替换条码为:" + OutBarCodeNO);

					} else {
						$("#txtResult").val("替换条码失败:" + data.Message);
						Audios();
					}
					$("#OutBar").val('');
					$("#InBar").val('');
					$("#OutBar").focus();
					plus.nativeUI.closeWaiting();
				}, function(error) {
					console.log("没有数据....");
					$("#OutBar").val('');
					$("#InBar").val('');
					$("#OutBar").focus();
					plus.nativeUI.closeWaiting();
				});


			}

		});
		//关闭等待框
		plus.nativeUI.closeWaiting();
		//显示当前页面
		//mui.currentWebview.show();
	});
}
//失败报警
function Audios() {
	var audio = new Audio('../../../fonts/baojin.mp3');

	audio.play();
}